<?php
/**
 * 登录检测行为钩子
 */

namespace app\admin\behavior;


use think\helper\Str;
use think\Request;
use think\Config;
load_trait('controller/Jump');
class LoginBehavior
{
    use \traits\controller\Jump;//类里面引入jump;类
    public function actionBegin(&$params)
    {
        //获取当前模块
        $request = Request::instance();
        $module = $request->module();
        $controller = $request->controller();
        $action = $request->action();
        $url = Str::lower($module . DS . $controller . DS . $action);
        $url = str_replace("\\", "/", $url);

        $config = Config::get('login_admin');

        //url请求登录页面,不做处理,否则其他页面进行登录校验
        $gateWays = explode(',', $config['user_auth_gateway']);
        if (!in_array($url, $gateWays)) {//不属于登录页面
            //登录校验
            $loginId = session($config['auth_uid']);
            if ($loginId) {
                // echo "已经登录";//不做处理
            } else {
               // echo "还没登录";//重定向登录页面
                $this->redirect($config['user_Login']);
            }
        }
    }
}